import HttpReqApi from "./http/HttpReqApi";
import { Session } from '/@/utils/storage';

export default class MonitorUnit {
    public static saveSession(dataArr) {

        let cfgRts=Session.get('loadDBCfgRoutes');
        if (!cfgRts){
            return;
        }

        let ipcamArr = [];

        let jsonData = { "msg": "操作成功", "code": 200, "data": [] };
        for (const obj of dataArr) {
            var jsonObj = { "id": obj.id, "url": obj.monitorAddr, "remark": obj.monitorName, "enabledFlv": false, "enabledHls": false, "mode": "javacv" };
            (jsonData.data as any).push(jsonObj);
        }
        const obj = jsonData;
        if (obj.data.length > 0) {
            for (let i = 0; i < obj.data.length; i++) {
                let robj = {
                    path: '/devlist/',
                    name: '',
                    component: '',
                    meta: {
                        title: '',
                        isLink: '',
                        isHide: false,
                        isKeepAlive: true,
                        isAffix: false,
                        isIframe: false,
                        auth: ['admin', 'test'],
                        icon: 'iconfont icon-gerenzhongxin',
                    },
                };
                robj.path += i;
                robj.name = obj.data[i].remark;
                robj.meta.title = robj.name;

                window.localStorage.setItem(robj.name,JSON.stringify({url:obj.data[i].url,remark:obj.data[i].remark}));

                ipcamArr.push(robj);
            }
        }
        let cfgRtsObj = {
            ipcamArr,
            webArr: cfgRts.webArr,
            rtdskArr: cfgRts.rtdskArr,
        };
        Session.set('loadDBCfgRoutes', cfgRtsObj);
    }

}